package us.gaaoc.framework.webapp.backingbeans.admin;

 
import java.util.List;
import java.util.Map;

import javax.faces.component.UIParameter;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import org.apache.log4j.Logger;
import org.hibernate.Hibernate;

import us.gaaoc.framework.businessmodel.Filing;
import us.gaaoc.framework.dao.ModelFacade;
import us.gaaoc.framework.dao.ModelFacadeHibernate; 
import us.gaaoc.framework.model.CaseRecord; 
import us.gaaoc.framework.webapp.backingbeans.BaseBackingBean;
 
/**
 * 
 * @author hea
 * @date Apr 19, 2006
 * @version: GAJE 1.5
 *
 */

public class ServedFilingPage extends BaseBackingBean {
	
	/**
	 * Properties
	 */
	private DataModel servedFilingDataTable ;
	
	private Logger LOG = Logger.getLogger(ServedFilingPage.class);

	private String courtUuid;
	
	/**
	 * Constructor
	 *
	 */ 
	public ServedFilingPage() {
		courtUuid = (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("courtUuid");
		//load data   
		//type = childenforcement    status = served
		List<Filing> newFilings = this.getModelFacade().findCaseFilingsByTypeAndStatus(1,4, courtUuid);	
		servedFilingDataTable = new ListDataModel();
		servedFilingDataTable.setWrappedData(newFilings);	 
	}

	/**
	 * This method navigates user to the Case Details Page
	 * @return String
	 */
  	@SuppressWarnings("unchecked")
	public String gotoCaseDetailPage(){
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
	 	Map requestMap = this.getFacesContext().getExternalContext().getRequestParameterMap();
	 	String caseUuid = ((String) requestMap.get("caseUuid"));
	 	sessionMap.put("caseUuid", caseUuid);
	 	sessionMap.put("from", "ServedFilingPage");			
		return "gotoCSECaseDetailsPage";
	}
	
  	/**
  	 * This method navigates user to the Child Enforcement Case Type Page
  	 * @return String
  	 */
	public String gotoChildEnforcementCaseTypePage() {
		return "gotoChildEnforcementCaseTypePage";
	}

	/**
	 * This method clears the case Record from the list and puts in the 
	 * trash can
	 * @return String
	 */
	public String clear(){
	 	Map requestMap = this.getFacesContext().getExternalContext().getRequestParameterMap();
	 	String caseUuid = ((String) requestMap.get("caseUuid"));
	 	this.getModelFacade().updateCaseRecordForClearCase(caseUuid, true, courtUuid);
	 	//HibernatePhaseListener.getSessionFactory().getCurrentSession().getTransaction().commit();
	  	return "stay";
	}

	/**
	 * Getter for property servedFilingDataTable
	 * @return
	 */
	public DataModel getServedFilingDataTable() {
		return servedFilingDataTable;
	}

	/**
	 * Setter for property servedFilingDataTable
	 * @param servedFilingDataTable
	 */
	public void setServedFilingDataTable(DataModel servedFilingDataTable) {
		this.servedFilingDataTable = servedFilingDataTable;
	}
	
	/**
	 * This method navigates user to the TrashCan
	 * @return String
	 */
	public String trashcan(){
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
		sessionMap.put("from2", "servedFiling");
		return "trashcan";
	}
	
	/**
	 * This method navigates user to the Case Record History Page
	 * @return String
	 */
	public String gotoHistoryPage() {
		Map sessionMap = this.getFacesContext().getExternalContext()
				.getSessionMap();
		Map requestMap = this.getFacesContext().getExternalContext()
				.getRequestParameterMap();
		String caseUuid = ((String) requestMap.get("caseUuid"));
		sessionMap.put("caseUuid", caseUuid);
		sessionMap.put("from", "ServedFilingPage");
		return "gotoCaseHistoryPage";
	}
}
